//
//  LoginVC.swift
//  whale
//
//  Created by topnet on 2022/3/29.
//

import UIKit

class LoginVC: LoginBaseVC {

    override func viewDidLoad() {
        super.viewDidLoad()
        
    }
    
    override func initUI() {
        super.initUI()
        titleLbl.text = "登录"
        nextBtn.setTitle("下一步", for: .normal)
        setupAgreementText()
        contentV.da.addSubviews(sub: [accountTf,
                                      agreementV,
                                      nextBtn,
                                      loginLbl])
    }
    
    override func actionNext() {
        super.actionNext()
        if !agreementV.btn.isSelected {
            return
        }
        if phone == nil {
            LogUtil.log("请输入手机号")
        }
        LogUtil.log(["登录成功": true])
        let vc = LoginCodeVC()
        vc.phone = phone
        push(vc)
    }
    
    override func initFrame() {
        super.initFrame()
        accountTf.left_right_offsetTop(titleLbl, x: 30.adapter).height(44.adapter)
        agreementV.left(accountTf.frame.minX-5.adapter).top(accountTf.frame.maxY+10.adapter).height(30.adapter).right(accountTf.frame.maxX)
        nextBtn.top(agreementV.frame.maxY + 30.adapter)
    }
    
    lazy var accountTf: LoginTextField = {
        let tf = LoginTextField(isPwd: false)
        tf.font = .font(15)
        tf.hintText = "请输入11位手机号"
        tf.isRightTextClosure = { [weak self] isRight, phone in
            self?.nextBtn.isEnabled = isRight
            self?.phone = phone
        }
        return tf
    }()
    
    private var phone: String?
}
